/*
* @Author: gaara  
* @Date: 2020-06-13 17:35:16  
*/

import { RawAsset } from "./RawAsset";
import { ImgUtil } from "../ImgUtil";

export class SpriteFrame extends RawAsset {

    rawTextureUuid: string;

    trimType: string;

    trimThreshold: number;

    rotated: boolean;

    offsetX: number;
    offsetY: number;
    trimX: number;
    trimY: number;
    width: number;
    height: number;

    rawWidth: number;
    rawHeight: number;
    borderTop: number;
    borderBottom: number;
    borderLeft: number;
    borderRight: number;

    spriteType?: string;

    constructor(path: string) {
        super(path);

        this.rawTextureUuid = "";
        this.trimType = "auto";
        this.trimThreshold = 0;
        this.rotated = false;

        this.offsetX = 0;
        this.offsetY = 0;
        this.trimX = 0;
        this.trimY = 0;
        this.width = 0;
        this.height = 0;

        this.rawWidth = 0;
        this.rawHeight = 0;
        this.borderTop = 0;
        this.borderBottom = 0;
        this.borderLeft = 0;
        this.borderRight = 0;

    }

    static version() {
        return '1.0.4';
    }


    importPathSub(path: string) {
        let size;
        try {
            size = ImgUtil.getImgSize(path);
        } catch (error) {
            throw '解析图片异常:' + path;
        }
        if (size) {
            this.width = this.rawWidth = size.width;
            this.height = this.rawHeight = size.height;
        }

        //暂时不用这种方案
/*         if (path.includes("s9g")) {
            let params = path.split('.')[0].split('_');
            if (params.length > 2) {
                this.borderTop = +params[2];
            }
            if (params.length > 3) {
                this.borderBottom = +params[3];
            }
            if (params.length > 4) {
                this.borderLeft = +params[4];
            }
            if (params.length > 5) {
                this.borderRight = +params[5];
            }
        } */
    }
}